package cj.primariaiquest.integration.endpoints;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import cj.primariaiquest.model.Ticket;

/**
 * Message endpoint used to transform tickets.
 * 
 * @author georgian.parvu
 * 
 */
public class TicketTransformer {
    private List<Ticket> canceledTickets = Collections
	    .synchronizedList(new ArrayList<Ticket>());

    /**
     * Method used to receive tickets. Checks if the given ticket has been
     * canceled and returns the appropriate ticket.
     * 
     * @param ticket
     *            Ticket
     * @return Ticket
     */
    public Ticket processTicket(Ticket ticket) {

	if (canceledTickets.contains(ticket)) {
	    ticket.setCanceled(true);
	}
	return ticket;
    }

    /**
     * Method used to receive and store canceled tickets
     * 
     * @param ticket
     *            canceled ticket
     * @return Ticket
     */
    public Ticket processCanceledTicket(Ticket ticket) {
	canceledTickets.add(ticket);
	return ticket;
    }
}
